package com.example.firstproject.controller;


import com.example.firstproject.entity.XuanKe;
import com.example.firstproject.service.XuanKeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private XuanKeService xuanKeService;


    @PostMapping("/choose")
    @ResponseBody
    public Map<String,Object> xuanKe(@RequestBody XuanKe xuanKe){
        Map<String,Object> retData = new HashMap<>();
        if(StringUtils.isEmpty(xuanKe.getStudentId()) ||  StringUtils.isEmpty(xuanKe.getCourseId() ) || xuanKe.getSeason() == 0){
            retData.put("code",500);
            retData.put("message","参数错误!");
        }else{
            retData = xuanKeService.xuanKe(xuanKe.getStudentId(),xuanKe.getCourseId(),xuanKe.getSeason());
        }
        log.info("retData ====> {}",retData);
        return retData;
    }
}





